import {
  Column,
  Entity,
  CreateDateColumn,
  UpdateDateColumn,
  DeleteDateColumn,
  PrimaryColumn,
  BeforeInsert,
} from 'typeorm';
import { ulid } from 'src/utils';

@Entity({ name: 'user' })
export class User {
  @PrimaryColumn({ length: 36, comment: 'ID' })
  id: string;

  @Column({ length: 36, comment: '手机号码' })
  phone: string;

  @Column({ length: 16, comment: '昵称' })
  nickname: string;

  @Column({ length: 64, comment: '头像' })
  avatar: string;

  @Column({ comment: '性别' })
  gender: number;

  @Column({ length: 16, comment: '出生年月' })
  borth_date: string;

  @Column({ comment: '身高' })
  height: number;

  @Column({ comment: '体重' })
  weight: number;

  @Column({ length: 16, comment: '工作' })
  work: string;

  @Column({ length: 16, comment: '学历' })
  education: string;

  @Column({ length: 16, nullable: true, comment: '家庭成员' })
  family_members: string;

  @Column({ comment: '当前状态' })
  status: number;

  @Column({ length: 32, comment: '工作地址(省/市)' })
  work_addr: string;

  @Column({ length: 32, comment: '居住地址' })
  live_addr: string;

  @Column({ length: 128, nullable: true, comment: '爱好' })
  hobby: string;

  @Column({ length: 4096, comment: '期望' })
  want: string;

  @Column({ length: 64, comment: '联系方式，手机/微信名片/微信号，需要加密' })
  contact: string;

  @CreateDateColumn({ comment: '创建时间' })
  created_at: Date;

  @UpdateDateColumn({ comment: '更新时间' })
  updated_at: Date;

  @DeleteDateColumn({ comment: '删除时间' })
  deleted_at: Date;

  // 需要先生成实体实例，才能触发@BeforeInsert钩子
  @BeforeInsert()
  generateId() {
    if (!this.id) this.id = ulid();
  }
}
